import torch
import torch.nn as nn


class Net(nn.Module):
    def __init__(self):
        super(Net, self).__init__()
        self.conv1 = nn.Conv2d(1, 10, 5)
        self.conv2 = nn.Conv2d(10, 20, 5)
        self.act = nn.ReLU()
        self.pool = nn.MaxPool2d(2, 2)
        self.fc = None

    def forward(self, x):
        x = self.pool(self.act(self.conv1(x)))
        x = self.pool(self.act(self.conv2(x)))
        x = torch.flatten(x, 1)
        if self.fc is None:
            self.fc = nn.Linear(x.shape[1], 10)
        x = self.fc(x)
        return x


model = Net()
print(model)
